package com.budwk.app.sqfw.models;

import cn.hutool.core.collection.CollectionUtil;
import com.budwk.app.sqfw.dto.PersonnelTagDTO;
import com.budwk.app.util.StrUtil;
import com.budwk.starter.common.openapi.annotation.ApiModel;
import com.budwk.starter.common.openapi.annotation.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.nutz.dao.entity.annotation.*;
import org.nutz.dao.interceptor.annotation.PrevInsert;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author LJT
 */
@Data
@Accessors(chain = true)
@Table("shequ.sqfw_datamange_person")
@Comment("人员信息excel数据")
@ApiModel(description = "人员信息excel数据")
public class Sqfw_datamange_person implements Serializable {

    private static final long serialVersionUID = 1L;

    @Column
    @Name
    @Comment("编号")
    @ApiModelProperty(description = "ID")
    @ColDefine(type = ColType.VARCHAR, width = 50)
    @PrevInsert(uu32 = true, nullEffective = true)
    private String id;

    @Column("person_id")
    @Comment("人员信息id")
    @ApiModelProperty(description = "人员信息id")
    @ColDefine(type = ColType.VARCHAR, width = 50)
    private String personId;

    @Column("special_mark")
    @Comment("特殊标志 (Special Mark)")
    @ApiModelProperty(description = "特殊标志 (Special Mark)")
    @ColDefine(type = ColType.PSQL_JSON)
    private List<PersonnelTagDTO> specialMark;

    @Column("excel_data")
    @Comment("excel_data")
    @ApiModelProperty(description = "excel在线数据")
    @ColDefine(type = ColType.TEXT)
    private String excelData;

    @Column("tags")
    @Comment("tags")
    @ApiModelProperty(description = "特殊人员标签")
    @ColDefine(type = ColType.TEXT)
    private String tags;

    @Column("excel_seg")
    @Comment("excel_seg")
    @ApiModelProperty(description = "excel结构标识,body, header")
    @ColDefine(type = ColType.VARCHAR, width = 10)
    private String excelSeg;

    @Column("del_flag")
    @Comment("删除标志")
    @ApiModelProperty(description = "删除标志")
    @ColDefine(type = ColType.BOOLEAN, width = 1)
    private Boolean delFlag;

    @Column("province")
    @Comment("省份 (居住地)")
    @ApiModelProperty(description = "省份 (居住地)")
    @ColDefine(type = ColType.VARCHAR, width = 50)
    private String province;

    @Column("city")
    @Comment("市 (居住地)")
    @ApiModelProperty(description = "市 (居住地)")
    @ColDefine(type = ColType.VARCHAR, width = 50)
    private String city;

    @Column("district")
    @Comment("区 (居住地)")
    @ApiModelProperty(description = "区 (居住地)")
    @ColDefine(type = ColType.VARCHAR, width = 50)
    private String district;

    @Column("county")
    @Comment("街道 (居住地)")
    @ApiModelProperty(description = "街道 (居住地)")
    @ColDefine(type = ColType.VARCHAR, width = 50)
    private String county;

    @Column("community")
    @Comment("社区 (居住地)")
    @ApiModelProperty(description = "社区 (居住地)")
    @ColDefine(type = ColType.VARCHAR, width = 50)
    private String community;

    @Column("update_date")
    @Comment("更新时间")
    @ApiModelProperty(description = "更新时间")
    @ColDefine(type = ColType.DATETIME)
    private LocalDateTime updateDate;

    public void setSpecialMark(List<PersonnelTagDTO> specialMark) {
        if (CollectionUtil.isNotEmpty(specialMark)) {
            List<PersonnelTagDTO> personnelTagDTOS = StrUtil.toListByJson(PersonnelTagDTO.class, specialMark.get(0));
            if (personnelTagDTOS != null) {
                this.specialMark = personnelTagDTOS;
                return;
            }
        }
        this.specialMark = specialMark;
    }
}
